#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QDebug>

#include <QQuickItem>
//#include

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    QList<QObject *> rootObjectsList = engine.rootObjects();
    if (rootObjectsList.isEmpty()) {
        qWarning()<<"Hasn't root object";
        return -1;
    }
    qDebug()<<rootObjectsList;

    QObject *quitButton = rootObjectsList.at(0)->findChild<QObject *>("quitButton");
    if (quitButton) {
        QObject::connect(quitButton, SIGNAL(clicked()), &app, SLOT(quit()));
    } else {
        qDebug()<<"Cann't find quitButton";
    }


    QObject *textLabel = rootObjectsList.at(0)->findChild<QObject *>("textLabel");
    if (textLabel) {
        bool ret = QMetaObject::invokeMethod(textLabel, "setText", Q_ARG(QString, "Hello Jake"));
        qDebug()<<"Call setText return - "<< ret;
        textLabel->setProperty("color", QColor::fromRgb(255, 0, 0));
        textLabel->setProperty("text", "Hello text");
        ret = QMetaObject::invokeMethod(textLabel, "doLayout");
        qDebug()<<"Call doLayout return - "<<ret;
    }

    return app.exec();
}

